
package com.contractmodule.servlet;
import com.contractmodule.bean.TbBackSection;
import com.contractmodule.dao.TbBackSectionDAO;
import com.usersmodule.bean.TbUsers;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import util.*;

public class TbBackSectionServlet extends HttpServlet{
    public void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        String method = request.getParameter("method")==null?"":request.getParameter("method");
        int userId=((TbUsers) request.getSession().getAttribute("Users")).getUserId();        
        if("add".equals(method)){
        String responsible=request.getParameter("responsible");
        String backSectionFlowInfo=request.getParameter("backSectionFlowInfo");
        String completionRates=request.getParameter("completionRates");
        String applicationAmount=request.getParameter("applicationAmount");
        String debitAmount=request.getParameter("debitAmount");
        String finalAmount=request.getParameter("finalAmount");
        String returnedAmount=request.getParameter("returnedAmount");
        String balance=request.getParameter("balance");
        String expectedBackSectionTime=request.getParameter("expectedBackSectionTime");
        String backSectionTime=request.getParameter("backSectionTime");
            if(new TbBackSectionDAO().add(new TbBackSection(responsible,backSectionFlowInfo,completionRates,applicationAmount,debitAmount,finalAmount,returnedAmount,balance,expectedBackSectionTime,backSectionTime,userId))){
            request.getSession().setAttribute("result", "添加成功");
            }else{            
            request.getSession().setAttribute("result", "添加失败");
            }
            goList(request, response);
        }
        if("del".equals(method)){
            if(UtilDAO.delin("Tb_BackSection", "BackSectionId", request.getParameter("delIds"))){            
            request.getSession().setAttribute("result", "删除成功");
            }else{            
            request.getSession().setAttribute("result", "删除失败");
            }
            goList(request, response);
        }
        if("edit".equals(method)){
        int backSectionId=Integer.parseInt(request.getParameter("backSectionId"));
        String responsible=request.getParameter("responsible");
        String backSectionFlowInfo=request.getParameter("backSectionFlowInfo");
        String completionRates=request.getParameter("completionRates");
        String applicationAmount=request.getParameter("applicationAmount");
        String debitAmount=request.getParameter("debitAmount");
        String finalAmount=request.getParameter("finalAmount");
        String returnedAmount=request.getParameter("returnedAmount");
        String balance=request.getParameter("balance");
        String expectedBackSectionTime=request.getParameter("expectedBackSectionTime");
        String backSectionTime=request.getParameter("backSectionTime");
            if(new TbBackSectionDAO().edit(new TbBackSection(backSectionId,responsible,backSectionFlowInfo,completionRates,applicationAmount,debitAmount,finalAmount,returnedAmount,balance,expectedBackSectionTime,backSectionTime,userId))){
            request.getSession().setAttribute("result", "修改成功");
            }else{            
            request.getSession().setAttribute("result", "修改失败");
            }
            goList(request, response);
        }
        if ("list".equals(method))goList(request, response);
        if ("listById".equals(method)) {
             request.getSession(true).setAttribute("tbBackSection",new TbBackSectionDAO().getTbBackSectionByBackSectionId(Integer.parseInt(request.getParameter("backSectionId"))));
            response.sendRedirect("ContractModule/TbBackSectionOperate.jsp");
    	}
        if("showadd".equals(method)){
            request.getSession(true).removeAttribute("tbBackSection");
            response.sendRedirect("ContractModule/TbBackSectionOperate.jsp");
        }
      
    }
    public void goList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	request.getSession(true).setAttribute("tbBackSectionList",new TbBackSectionDAO().getTbBackSectionAll());
        response.sendRedirect("ContractModule/TbBackSectionList.jsp");
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }// end method doGet
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }// end method doPost
}
